package test;

public class variables_primitive {
	/*******************************************************************************
	 * Software: variables_primitive.java
	 * Version:  1.0
	 * Date:     Feb 14, 2010 11:47:19 AM
	 * License:  none specified yet.
	 *
	 * PURPOSE:
	 * REQUIREMENTS WHAT ELSE IS NEEDED:
	 * TODO:
	 * FEATURES:
	 *******************************************************************************/

	public variables_primitive() {

	}
	
	static boolean THIS_BOOLEAN_IS_AUTO_INITIALIZED; // in contrast to local variable BOOLEAN this THIS_BOOLEAN_IS_AUTO_INITIALIZED is AUTOMATICALLY INITIALIZED with default value 'false'
	static char CHAR_AUTO_INIT; // auto initialized with default value: '\u0000'
	static byte BYTE_AUTO_INIT; // auto initialized with default value: 0
	static short SHORT_AUTO_INIT; // auto initialized with default value: 0 
	static int INT_AUTO_INIT; // auto initialized with default value: 0
	static long LONG_AUTO_INIT; // auto initialized with default value: 0L 
	static float FLOAT_AUTO_INIT; // auto initialized with default value: 0.0f
	static double DOUBLE_AUTO_INIT; // auto initialized with default value: 0.0f
	static String STRING_AUTO_INIT; // auto initialized with default value: null

	public static void main(String[] args)
	{
		/**
		 * http://java.sun.com/docs/books/tutorial/java/nutsandbolts/variablesummary.html
		 * The eight primitive data types are: byte, short, int, long, float, double, boolean, and char.
		 **/
		/** here is a bunch of uninitialized so called 'primitive' variables **/
		boolean BOOLEAN; // in contrast to variable THIS_BOOLEAN_IS_AUTO_INITIALIZED, this 'local' variable is NOT AUTOMATICALLY INITIALIZED.
		char CHAR;
		byte BYTE;
		short SHORT;
		int INT;
		long LONG;
		float FLOAT;
		double DOUBLE;		
		String STRING;

		/**
		 * The java.lang.String class represents character strings.
		 * The compiler will assign a reasonable default value for fields of the above types;
		 * for local variables, a default value is never assigned.
		 * A literal is the source code representation of a fixed value.
		 * An array is a container object that holds a fixed number of values of a single type.
		 * The length of an array is established when the array is created. After creation, its length is fixed.
		 * **/

		// what default values do EMPTY variables have?

		/**
		# Field variables (class members) are automatically initialized to default values
		# Local variables (method or constructor variables) are not automatically initialized
		# Arrays, whether field or local variables, are automatically initialized to the default values of their declared type
		**/
		// when trying to acces an uninitialized variable, an error is thrown: System.out.println(BOOLEAN); // default value is false
		// causes compile error if not explicitly initialized, it's not even possible to catch that error.
		// so the following does not work:
		/**
		try
		{
			System.out.println("Local variable " + BOOLEAN + " is initialized."); // The local variable BOOLEAN may not have been initialized
			// yes variable is allready initialized
		}
		catch (Exception e) {
			// TODO: handle exception
			System.out.println("Local variable BOOLEAN uninitalized, Error thrown: "+e);
			System.out.println("Asigning default value: false");
			BOOLEAN = false;
			// no variable is uninitialized -> asign a value
		}
		**/

		/** init global variables are automatically initialized with default values. **/
		System.out.println(THIS_BOOLEAN_IS_AUTO_INITIALIZED); // false
		System.out.println(CHAR_AUTO_INIT); // ''
		System.out.println(BYTE_AUTO_INIT); // 0
		System.out.println(SHORT_AUTO_INIT); // 0
		System.out.println(INT_AUTO_INIT);// 0
		System.out.println(LONG_AUTO_INIT);// 0 
		System.out.println(FLOAT_AUTO_INIT);// 0.0
		System.out.println(DOUBLE_AUTO_INIT);// 0.0
		System.out.println(STRING_AUTO_INIT); // null
		
		/** init local variables **/
		System.out.println(BOOLEAN = false);
		System.out.println(CHAR = 'c');
		System.out.println(BYTE = 0);
		System.out.println(SHORT = 1);
		System.out.println(INT = 2);
		System.out.println(LONG = 3);
		System.out.println(FLOAT = 5);
		System.out.println(DOUBLE = 5);

		/** BOOLEAN**/
		/** range of value:
				boolean 1 true oder false 
		/** default value: false **/
		System.out.println(THIS_BOOLEAN_IS_AUTO_INITIALIZED);
	    
		/** CHAR **/
		/** range of value:
		 * 		char 2 16-Bit Unicode Zeichen (0x0000...0xffff) **/

		/** default value: '' (nothing) or UTF-8 Code: '\u0000' **/
		System.out.println(CHAR_AUTO_INIT);

		/** Wunsch nach Portabilität stand ganz oben auf der Liste der Designziele. Konsequenterweise wurde der Typ
		 * char in Java daher bereits von Anfang an 2 Byte groß gemacht und speichert seine Zeichen auf der Basis des Unicode-Zeichensatzes.
		 * 
		 * Weiterhin können beliebige Unicode-Escape-Sequenzen der Form \\uxxx angegeben werden (das erste \ weg lassen dient nur dazu
		 * , damit der compiler sich nicht über diesen kommentar ermault.
		 * wobei xxxx eine Folge von bis zu 4 hexadezimalen Ziffern ist.
		 * So steht beispielsweise \u000a für die Zeilenschaltung und \u0020 für das Leerzeichen.
		 **/

		CHAR = '\u0000'; // asign unicode / UTF-8 to CHAR of specific number, UTF-8 (8-bit  UCS/Unicode Transformation Format) is a variable-length character encoding for Unicode. 

		int j=0;

		double how_many_possible_chars = Math.pow(2,8);

		for(int i=32; i<=how_many_possible_chars;i++)
		{
			System.out.print(i + ":\t"  + (char)i +"   ");
			j++;
		
			if(j>5)
			{
				System.out.println();
				j=0;
			}
		}

		/** BYTE **/
		/** range of value:
			byte 1 –2^7 bis 2^7 – 1 (–128...127) 

			default value: 0 **/
			System.out.println(BYTE_AUTO_INIT);
		/**

			Für 
			float und double ist das Vorzeichen nicht angegeben, da die kleinsten und größten 
			darstellbaren Zahlen sowohl positiv wie auch negativ sein können. Mit anderen Worten: 
			Die Wertebereiche unterscheiden sicht nicht in Abhängigkeit vom Vorzeichen.
			file:///Volumes/DATA/JAVA/DOC/HTML/javabuch_JDK_1.4_2000/hjp3html/k100024.html
			Strings:
			"This is a valid string", 'this is not a valid string'
			only double quotes are valid.
		**/

		/** SHORT **/
		/** range of value:
			short 2 –2^15 bis 2^15 – 1 (–32768...32767)
			default value: 0 **/
		System.out.println(SHORT_AUTO_INIT); 

			
		/** INT **/ 
		/** range of value:
			int 4 –2^31 bis 2^31 – 1 (–2147483648...2147483647)
			default value: 0 **/			 
		System.out.println(INT_AUTO_INIT);
	
		/** LONG **/
		/** range of value:
				long 8 –2^63 bis 2^63 – 1 (–9223372036854775808...9223372036854775807)
				default value: 0 **/
		System.out.println(LONG_AUTO_INIT); 

		/** FLOAT **/
		/** range of value:
				float 4 1,40239846E-45f...3,40282347E+38f
		default value: 0 **/				 
		System.out.println(FLOAT_AUTO_INIT);
				 
		/** DOUBLE **/ 
		/** range of value:
			double 8 4,94065645841246544E-324... 1,79769131486231570E+308 
			default value: 0 **/				 
		System.out.println(DOUBLE_AUTO_INIT);

	    /** STRING **/
		System.out.println(STRING_AUTO_INIT);

		/** In einer Methode können Parameter oder lokale Variablen mit dem Modifizierer final deklariert werden.
		 * Dieses zusätzliche Schlüsselwort verbietet nochmalige Zuweisungen an diese Variable, sodass sie nicht mehr verändert werden kann.
		 */
	    int i = 2; 
	    final int UNCHANGABLE = 3; 
	    i = 3; 
		// UNCHANGABLE = 4;       // führt zu einem Fehler, "The final local variable j cannot be assigned. It must be blank and not using a compound assignment"
		//  a = 2;       // führt zu einem Fehler

	}
}
